//index.js
//获取应用实例
const app = getApp()
var storeLists = require("../../data/storeList.js");
//定义一个数组，这个数组写在data里面，用于页面上面的加载
Page({
  data: {
    userInfo: {},
    //swiper
    imgUrls: [
      '/images/banners1.png',
      '/images/banners2.png',
      '/images/banners3.png',
    ],
    indicatorDots: true,//导航点
    autoplay: true,
    circular: true, //衔接滑动
    interval: 5000,
    duration: 1000,
    //swiper
    shujulist: [],
    canIUse:''
    
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    //获取用户信息
    console.log(app.globalData.userInfo);
    if ((app.globalData.userInfo == "") || (app.globalData.userInfo == undefined) || (app.globalData.userInfo == null)){
      this.setData({
        canIUse: false
      })
    }
     this.setData({
       shujulist: storeLists.data
     })
  },
  enterStoreinfo:function(e){
    var data = e.currentTarget.dataset;
    var adress = data.adress;
    var distance = data.distance;
    var img = data.img;
    var name = data.name;
    var volume = data.volume;
    wx.navigateTo({
      url: '/pages/storeinfo/storeinfo?name=' + name + '&volume=' + volume + '&distance=' + distance + '&adress=' + adress + '&img=' + img+'',
    })
  },
  enterMine:function(){
    wx.navigateTo({
      url: '/pages/mine/mine',
    })
  }, 
  bindGetUserInfo: function (res){//获取用户信息
    var userinfos = res.detail.userInfo;
    if (userinfos != undefined) {

      console.log("获取用户信息成功", res)
      // 获取用户信息
      app.globalData.userInfo = res.detail.userInfo;

      app.globalData.isLogin = true;
      app.globalData.userName = res.detail.userInfo.nickName;
      app.globalData.userHeadImg = res.detail.userInfo.avatarUrl;
      var adress = res.detail.userInfo.province + res.detail.userInfo.city + res.detail.userInfo.country;
      app.globalData.userAdress = adress;

      wx.setStorageSync(userInfo, res.detail.userInfo);
      wx.setStorageSync(isLogin, true);
      wx.setStorageSync(userName, res.detail.userInfo.nickName);
      wx.setStorageSync(userHeadImg, res.detail.userInfo.avatarUrl);
      wx.setStorageSync(userAdress, adress);

      this.setData({
        canIUse:false
      })

    } else {
      this.setData({
        canIUse: false
      })
      // false 默认头像
      wx.showToast({
        title: '未授权成功哦',
      })
      
    }
  }


})
